package app.stock.tools;

import app.common.Util;
import app.stock.common.Transaction;
import app.stock.common.TransactionTypes;

public class StockCalculator {

    public static void caluclate(Transaction tx) {
        if (tx.code.equals(TransactionTypes.mairu) && tx.amount < 0) {
            tx.amount = -tx.amount;
        } else if (tx.code.equals(TransactionTypes.maichu) && tx.amount > 0) {
            tx.amount = -tx.amount;
        } else if (tx.code.equals(TransactionTypes.zhuanru) && tx.sum1 < 0) {
            tx.sum1 = -tx.sum1;
        } else if (tx.code.equals(TransactionTypes.zhuanchu) && tx.sum1 > 0) {
            tx.sum1 = -tx.sum1;
        }
        if (tx.sum1 == 0) {
            tx.sum1 = -(tx.price * tx.amount);
        }
        tx.sum1 = Util.toFixedDigitsFloat(tx.sum1, 2).floatValue();
        if (tx.shouxufei > 0) {
            tx.shouxufei = -tx.shouxufei;
        }
        if (tx.yinhuashui > 0) {
            tx.yinhuashui = -tx.yinhuashui;
        }
        if (tx.guohufei > 0) {
            tx.guohufei = -tx.guohufei;
        }
        tx.sum2 = tx.sum1 + tx.shouxufei + tx.yinhuashui + tx.guohufei;
        tx.sum2 = Util.toFixedDigitsFloat(tx.sum2, 2).floatValue();
    }
}
